<!-- 会议列表 -->
<template>
  <app-page card full>
    <app-page-main>
      <template #header>
        <div class="app-query">
          <el-form
            :inline="true"
            :model="pageData.query"
            @submit.prevent="pageActions.handleSearch"
            @keyup.enter="pageActions.handleSearch"
          >
            <el-form-item label="会议名称">
              <el-input v-model="pageData.query.meetName" placeholder="请输入" clearable></el-input>
            </el-form-item>
            <el-form-item label="会议室名称">
              <el-input v-model="pageData.query.roomName" placeholder="请输入" clearable></el-input>
            </el-form-item>
            <el-form-item label="会议时间" style="width: 500px">
              <DatePicker v-model:start="pageData.query.startTime" v-model:end="pageData.query.endTime" />
            </el-form-item>
            <el-form-item label="会议状态">
              <el-select
                v-model="pageData.query.status"
                clearable
                :value-on-clear="() => null"
                :empty-values="[null]"
              >
                <el-option label="全部" value="" />
                <el-option label="待开始" value="0" />
                <el-option label="进行中" value="1" />
                <el-option label="已完成" value="2" />
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="search" @click="pageActions.handleSearch">搜索</el-button>
              <el-button icon="refresh" @click="pageActions.handleReset">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
        <div class="app-action">
          <el-button
            type="primary"
            plain
            icon="plus"
            @click="$router.push({ path: `${$route.path}/edit`, query: { rootPath: $route.path } })"
          >
            添加
          </el-button>
        </div>
      </template>

      <el-table v-loading="pageData.loading" :data="pageData.data">
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column
          prop="meetName"
          label="会议名称"
          :show-overflow-tooltip="{ popperClass: 'app-table-tooltip' }"
        ></el-table-column>
        <el-table-column
          prop="roomName"
          label="会议室名称"
          :show-overflow-tooltip="{ popperClass: 'app-table-tooltip' }"
        ></el-table-column>
        <el-table-column label="位次图">
          <template #default="{ row }">
            <el-link type="primary" @click="onPage('/user', row)">参会人员</el-link>
          </template>
        </el-table-column>
        <el-table-column label="会议消息">
          <template #default="{ row }">
            <el-link type="primary" @click="onPage('/notice', row)">会议消息</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="organize" label="会议议程">
          <template #default="{ row }">
            <el-link type="primary" @click="onPage('/agenda', row)">会议议程</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="organize" label="会议资料">
          <template #default="{ row }">
            <el-link type="primary" @click="onPage('/file/category', row)">会议资料</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="organize" label="会议投票">
          <template #default="{ row }">
            <el-link type="primary" @click="onPage('/vote', row)">会议投票</el-link>
          </template>
        </el-table-column>
        <el-table-column label="会议状态">
          <template #default="{ row }">
            <el-tag :type="row.status === 1 ? 'success' : row.status === 2 ? 'danger' : 'primary'">{{
              row.status === 1 ? '进行中' : row.status === 2 ? '已结束' : '待开始'
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="会议呼叫" class-name="call-column">
          <template #default="{ row }">
            <el-badge :value="row.callCount" :show-zero="false" :offset="[5, 0]" :max="9" class="badge-item">
              <el-link type="primary" @click="onPage('/call', row)">会议呼叫</el-link>
            </el-badge>
          </template>
        </el-table-column>
        <el-table-column
          label="会议时间"
          :formatter="getTime"
          :show-overflow-tooltip="{ popperClass: 'app-table-tooltip' }"
        />
        <el-table-column label="操作" width="260">
          <template #default="{ row }">
            <el-button
              v-if="row.status === 0"
              link
              type="primary"
              icon="edit"
              @click="
                $router.push({ path: `${$route.path}/edit`, query: { id: row.id, rootPath: $route.path } })
              "
            >
              编辑
            </el-button>

            <el-button link type="primary" icon="connection" @click="copyLink($event, row)">
              会议链接
            </el-button>
            <el-button link type="primary" icon="delete" @click="pageActions.handleDelete(row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </app-page-main>

    <template #footer>
      <div class="app-toolbar" v-if="$route.query.from">
        <el-button type="primary" @click="$router.go(-1)">返回</el-button>
      </div>
      <el-pagination
        @size-change="pageActions.handleSizeChange"
        @current-change="pageActions.handlePageChange"
        :current-page="pageData.page"
        :page-size="pageData.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageData.total"
      />
    </template>
  </app-page>
</template>

<script setup>
import { usePageList } from 'jax-node'
import Clipboard from 'clipboard'
import { ElMessage } from 'element-plus'
import DatePicker from '@/components/form/DatePicker.vue'

const { pageData, pageActions } = usePageList({
  query: {
    status: '',
  },
})

const getTime = row => {
  return `${row.startTime}至${row.endTime}`
}

const router = useRouter()
const route = useRoute()
const onPage = (path, row) => {
  router.push({
    path: `${route.path}${path}`,
    query: { id: row.id, rootPath: route.path, roomId: row.roomId },
  })
}

const copyLink = (e, row) => {
  const clipboard = new Clipboard(e.target, {
    text: () => {
      return `${location.origin}/h5/home?meetId=${row.id}`
    },
  })
  clipboard.on('success', () => {
    ElMessage.success('复制成功')
    clipboard.destroy()
  })
  clipboard.on('error', () => {
    ElMessage.error('复制失败')
    clipboard.destroy()
  })
  clipboard.onClick({ currentTarget: e.target })
}
</script>

<style lang="scss" scoped>
:deep(.call-column) {
  .cell {
    line-height: normal;
    overflow: visible;
  }
}
</style>
